package com.tengju.bff.infrastructure.export.repo;

import com.tengju.bff.infrastructure.export.convert.ExportCrmDealerInfoVoConvert;
import com.tengju.bff.interfaces.manage.crm.dealer.facade.CrmDealerInfoFacade;
import com.tengju.bff.interfaces.manage.crm.dealer.form.CrmDealerInfoExportForm;
import com.tengju.bff.interfaces.manage.crm.dealer.vo.ExportCrmDealerInfoVO;
import com.tengju.bff.interfaces.shared.export.DealerInfoExportQuery;
import com.tengju.export.domain.record.ExportDataSourceRepository;
import com.tengju.export.domain.record.Query;
import com.tengju.export.domain.record.Table;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 李大仙
 * @date: 2021/8/23 2:39 下午
 */
@Service("dealerInfoExportDataSourceRepository")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class DealerInfoExportDataSourceRepository implements ExportDataSourceRepository {

    private final CrmDealerInfoFacade crmDealerInfoFacade;

    @Override
    public Table batchFindDataSource(Query query) {
        DealerInfoExportQuery exportQuery = (DealerInfoExportQuery) query;
        CrmDealerInfoExportForm form = new CrmDealerInfoExportForm();
        form.setGenSecIdCodes(exportQuery.getGenSecIdCodes());
        form.setIdCode(exportQuery.getIdCode());
        form.setLevel(exportQuery.getLevel());
        form.setStartTime(exportQuery.getStartTime());
        form.setEndTime(exportQuery.getEndTime());
        form.setAreaSupIdCode(exportQuery.getAreaSupIdCode());
        form.setMobile(exportQuery.getMobile());
        form.setNickName(exportQuery.getNickName());
        form.setInviteCode(exportQuery.getInviteCode());
        form.setWeChat(exportQuery.getWeChat());
        form.setGoodNumber(exportQuery.getGoodNumber());
        List<ExportCrmDealerInfoVO> crmDealerInfoVOList = crmDealerInfoFacade.exportCrmDealerInfoVOList(form);

        Table table = ExportCrmDealerInfoVoConvert.convert(crmDealerInfoVOList);
        return table;
    }
}
